package com.pzh.assignment.common.bean.vo;

import com.pzh.assignment.common.bean.GlobalConstant;
import com.pzh.assignment.entity.Class;
import lombok.Data;

import java.time.format.DateTimeFormatter;


@Data
public class ClassVO {
    private Integer id;

    private Integer majorId;

    private Integer grade;

    private Integer classNum;

    private Integer peopleNum;

    private String createTime;

    private String updateTime;

    public static ClassVO valueOf(Class clazz) {
        ClassVO vo = new ClassVO();
        vo.setId(clazz.getId());
        vo.setMajorId(clazz.getMajorId());
        vo.setGrade(clazz.getGrade());
        vo.setClassNum(clazz.getClassNum());
        vo.setPeopleNum(clazz.getPeopleNum());
        if (clazz.getCreateTime() != null) {
            vo.setCreateTime(clazz.getCreateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        if (clazz.getUpdateTime() != null) {
            vo.setUpdateTime(clazz.getUpdateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        return vo;
    }
}
